package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_6_13_Training {
    //乘积为正数的最长子数组长度
    public int getMaxLen(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n+1];
        int[] fp = new int[n+1];
        int max = -1;
        for (int i = 1; i <= n; i++) {
            if(nums[i-1]==0){
                dp[i] = 0;
                fp[i] = 0;
            }else if(nums[i-1]<0){
                if(fp[i]==0){
                    dp[i] = dp[i-1];
                    fp[i] = fp[i-1]+1;
                }else{
                    dp[i] = Math.max(dp[i-1],fp[i-1]+1);
                    fp[i] = Math.max(fp[i-1],dp[i-1]+1);
                }
            }else {
                dp[i] = dp[i-1]+1;
                if(fp[i-1]==0){
                    fp[i] = fp[i-1];
                }else {
                    fp[i] = fp[i-1]+1;
                }
            }
            max = Math.max(max,dp[i]);
        }
        return max;
    }
}





